<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/13 0013
 * Time: 下午 3:09
 */
namespace app\common\validate;

use app\lib\exception\ParameterException;

class createStoreValidate extends BaseValidate{


    /**
     * @var array
     * ["store"] => array(11) {
    ["name"] => string(3) "eee"
    ["imgUrl"] => string(49) "https://img.lksjjh.com/img2018091315251352701.png"
    ["businessLicense"] => string(49) "https://img.lksjjh.com/img2018091315254648798.png"
    ["address"] => string(35) "南湖商务宾馆(南湖雅园店)"
    ["addressNumb"] => string(5) "wwwww"
    ["lat"] => float(30.49978)
    ["lng"] => float(114.34142)
    ["phone"] => string(11) "02741252145"
    ["businessHours"] => string(11) "10:00-23:00"
    ["contact"] => string(0) ""
    ["contactPhone"] => string(0) ""
    }
     */

    protected $rule = [
        'store' => 'checkStores',
        'typeId' => 'require|isNotEmpty',
    ];

    protected $message = [
        'typeId' => '必须选择店铺类型',
    ];

    protected $singRule = [
        'name' => 'require|isNotEmpty',
        'imgUrl' => 'require|isNotEmpty',
        'province' => 'require|isNotEmpty',
        'city' => 'require|isNotEmpty',
        'district' => 'require|isNotEmpty',
        'addressNumb' => 'require|isNotEmpty',
        'phone' => 'require|isNotEmpty',
        'businessHours' => 'require|isNotEmpty',
        'contact' => 'require|isNotEmpty',
        'contactPhone' => 'require|isNotEmpty'

    ];

    protected function checkStores($values){
        if(!is_array($values) || empty($values)){
            throw new ParameterException([
                'msg' => '店铺参数不合法'
            ]);
        }

        $this->checkStore($values);

        return true;

    }

    protected function checkStore($value){
        $validate = new BaseValidate($this->singRule);
        $result = $validate->check($value);
        if(!$result){
            throw new ParameterException([
                'msg' => '店铺参数错误'
            ]);
        }
    }
}